%note that the number of Stocks must be larger than 3
function [beta] = BetaShrinkage(rListStock, rIndex)

    %n is the number of Stocks
    %m is the length of each Stock
    [m,n] = size(rListStock);
    
    %estimate betaOLS of each Stock
    bOLS = BetaOLS(rListStock,rIndex);
    %calculate the mean of all beta
    bmean = mean(bOLS);
    %estimate the parameter alpha
    %v = (1/k)*(bOLS - bmean).^2;
    %alpha = 1-(k-3)*v./(bOLS - bmean).^2
    alpha = 3/n;
    
    for i = 1:n
        beta(i) = bmean + alpha*(bOLS(i) - bmean);
    end